using System;
using System.Configuration;
using System.Xml;

namespace Edge.Common.Mail.Impl
{
    public class MailConfigSection : ConfigurationSection
    {
        private XmlElement xmlElement;

        public XmlElement XmlElement
        {
            get
            {
                return xmlElement;
            }
            protected set
            {
                xmlElement = value;
            }
        }

        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            //            ConfigurationHelpers.SetIsPresent(this);
            XmlDocument document = new XmlDocument();
            this.XmlElement = (XmlElement)document.ReadNode(reader);
        }


        protected override bool SerializeToXmlElement(XmlWriter writer, string elementName)
        {
            bool flag = this.XmlElement != null;
            if (flag && (writer != null))
            {
                if (!string.Equals(elementName, "xmlElement", StringComparison.Ordinal))
                {
                    writer.WriteStartElement(elementName);
                }
                using (XmlNodeReader reader = new XmlNodeReader(this.XmlElement))
                {
                    writer.WriteNode(reader, false);
                }
                if (!string.Equals(elementName, "xmlElement", StringComparison.Ordinal))
                {
                    writer.WriteEndElement();
                }
            }
            return flag;
        }

        public string Contents
        {
            get
            {
                return this.XmlElement.InnerText;
                //                return this.SectionInformation.GetRawXml();
            }
        }
    }
}